package com.hc.wdj.auth.server.manager;

import com.hc.wdj.auth.server.config.OAuthServerConfig;
import com.hc.wdj.auth.server.data.generate.OAuthDataGenerate;
import com.hc.wdj.auth.server.data.generate.OAuthDataGenerateDefaultImpl;
import com.hc.wdj.auth.server.data.loader.OAuthDataLoader;
import com.hc.wdj.auth.server.data.loader.OAuthDataLoaderDefaultImpl;
import com.hc.wdj.auth.server.data.resolver.OAuthDataResolver;
import com.hc.wdj.auth.server.data.resolver.OAuthDataResolverDefaultImpl;
import com.hc.wdj.auth.server.template.OAuthTemplate;

/**
 * @author ryanwdj
 * @since 2024/11/17
 */
public class OAuthManager {

    /**
     * OAuth2 数据加载器 Bean
     */
    private static volatile OAuthDataLoader dataLoader;
    public static OAuthDataLoader getDataLoader() {
        if (dataLoader == null) {
            synchronized (OAuthDataLoader.class) {
                if (dataLoader == null) {
                    setDataLoader(new OAuthDataLoaderDefaultImpl());
                }
            }
        }
        return dataLoader;
    }
    public static void setDataLoader(OAuthDataLoader dataLoader) {
        OAuthManager.dataLoader = dataLoader;
    }

    /**
     * OAuth数据解析器
     */
    private static volatile OAuthDataResolver dataResolver;
    public static OAuthDataResolver getDataResolver(){
        if(dataResolver == null){
            synchronized (OAuthManager.class){
                if(dataResolver == null){
                    setDataResolver(new OAuthDataResolverDefaultImpl());
                }
            }
        }
        return dataResolver;
    }
    public static void setDataResolver(OAuthDataResolver dataResolver){
        OAuthManager.dataResolver = dataResolver;
    }

    /**
     * OAuth2模版方法 Bean
     */
    private static volatile OAuthTemplate template;
    public static OAuthTemplate getTemplate(){
        if(template == null){
            synchronized (OAuthManager.class){
                if(template == null){
                    setTemplate(new OAuthTemplate());
                }
            }
        }
        return template;
    }
    public static void setTemplate(OAuthTemplate template){
        OAuthManager.template = template;
    }


    /**
     * OAuth2 数据构建器 Bean
     */
    private static volatile OAuthDataGenerate dataGenerate;
    public static OAuthDataGenerate getDataGenerate(){
        if(dataGenerate == null){
            synchronized (OAuthManager.class){
                if(dataGenerate == null){
                    setDataGenerate(new OAuthDataGenerateDefaultImpl());
                }
            }
        }
        return dataGenerate;
    }
    public static void setDataGenerate(OAuthDataGenerate dataGenerate){
        OAuthManager.dataGenerate = dataGenerate;
    }


    /**
     * OAuth2 配置 Bean
     */
    private static volatile OAuthServerConfig serverConfig;
    public static OAuthServerConfig getServerConfig(){
        if(serverConfig == null){
            synchronized (OAuthManager.class){
                if(serverConfig == null){
                    setServerConfig(new OAuthServerConfig());
                }
            }
        }
        return serverConfig;
    }
    public static void setServerConfig(OAuthServerConfig serverConfig){
        OAuthManager.serverConfig = serverConfig;
    }
}
